package model.world;

import java.awt.Point;
import java.io.Serializable;

import model.csExceptions.NotEnoughGrenades;
import model.csExceptions.TooMuchGrenades;
import model.enumTypes.CSGrenadeType;
import model.path.CSPlayerPath;



/**
 * This class implements a CS player.
 * It is quite simple.
 * 
 * @author Urbanek Lucas (aka NaG)
 */
public class CSPlayer implements Serializable {
	private String name;
	private CSStuff stuff;
	private CSPlayerPath path;
	
	/**
	 * The CSPlayer builder needs the roundTime and the
	 * player's spawn.
	 * 
	 * @param roundTime
	 * @param spawn
	 */
	public CSPlayer(String name_, double roundTime, Point spawn) {
		name = name_;
		stuff = new CSStuff();
		path = new CSPlayerPath(roundTime, spawn, this);
	}
	
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	
	public Point getCurrentPosition() {
		return path.getCurrentPosition();
	}
	
	public CSPlayerPath getPath() {
		return path;
	}
	
	public int getFBs() {
		return stuff.getFBs();
	}
	
	public int getHEs() {
		return stuff.getHEs();
	}
	
	public int getSGs() {
		return stuff.getSGs();
	}
	
	public void setFBs(int n) {
		stuff.setFBs(n);
	}
	
	public void setHEs(int n) {
		stuff.setHEs(n);
	}
	
	public void setSGs(int n) {
		stuff.setSGs(n);
	}
	
	public boolean canThrowGrenade(CSGrenadeType type) {
		if (type == CSGrenadeType.FB)
			return canThrowFB();
		if (type == CSGrenadeType.HE)
			return canThrowHE();
		if (type == CSGrenadeType.SG)
			return canThrowSG();
		return false;
	}
	
	public boolean canThrowFB() {
		return stuff.canThrowFB(path.getFBEventsCount());
	}
	
	public boolean canThrowHE() {
		return stuff.canThrowHE(path.getHEEventsCount());
	}
	
	public boolean canThrowSG() {
		return stuff.canThrowSG(path.getSGEventsCount());
	}
	
	public void throwGrenade(CSGrenadeType type) throws NotEnoughGrenades {
		if (type == CSGrenadeType.FB)
			throwFB();
		if (type == CSGrenadeType.HE)
			throwHE();
		if (type == CSGrenadeType.SG)
			throwSG();
	}
	
	public void throwFB() throws NotEnoughGrenades {
		if (path.getCurrentTime() == 0 && path.getFBEventsCount()==stuff.getFBs())
			throw new NotEnoughGrenades();
		stuff.throwFB();
	}
	
	public void throwHE() throws NotEnoughGrenades {
		if (path.getCurrentTime() == 0 && path.getHEEventsCount()==stuff.getHEs())
			throw new NotEnoughGrenades();
		stuff.throwHE();
	}
	
	public void throwSG() throws NotEnoughGrenades {
		if (path.getCurrentTime() == 0 && path.getSGEventsCount()==stuff.getSGs())
			throw new NotEnoughGrenades();
		stuff.throwSG();
	}
	
	public void giveGrenade(CSGrenadeType type) throws TooMuchGrenades {
		if (type == CSGrenadeType.FB)
			giveFB();
		if (type == CSGrenadeType.HE)
			giveHE();
		if (type == CSGrenadeType.SG)
			giveSG();
	}
	
	public void giveFB() throws TooMuchGrenades {
		stuff.giveFB();
	}
	
	public void giveHE() throws TooMuchGrenades {
		stuff.giveHE();
	}
	
	public void giveSG() throws TooMuchGrenades {
		stuff.giveSG();
	}
}
